<?php
/**
 * User: Netman
 * Date: 14-3-27
 * Time: 下午9:53
 */

class Stourweb_Controller extends Class_Controller {

    protected $cmsurl;

    //平台编码
    protected $platform_no=5;
    /*
     * before
     */
    public function before()
    {
        parent::before();
        $this->cmsurl = URL::site();
         //常用变量赋值
        $this->assign('cmsurl', $this->cmsurl);
        $this->assign('webname', $GLOBALS['cfg_webname']);
        $params = $this->request->param('params');
        $this->params = $this->analyze_param($params);
        $controller = $this->request->controller();
        $action = $this->request->action();
        $directory = $this->request->directory();
        //将PC站点关闭检测下沉至PC底层控制层
        if (empty($GLOBALS['cfg_web_open']))
        {
            exit('<meta charset="utf-8"><p align="center">网站维护中,暂时关闭.请稍后访问</p>');
        }



        $client_ip =  St_Client::get_ip();

        if($GLOBALS['cfg_force_login']==1
            && $directory!='member'
            && !in_array($controller,array('pub','city','common','error'))
            && St_Functions::is_url_need_verify()
            && $client_ip!=$_SERVER['SERVER_ADDR']
            && (($directory==''||$directory=='pc')||strpos($directory,"pc/api/v2")>0)
        )
        {
            $user = Model_Member::check_login();
            if (empty($user['mid']) )
            {
                header('Location:'.$GLOBALS['cfg_basehost'].'/member/login');
                exit;
            }
        }



        if($GLOBALS['cfg_member_force_verify']==1
            && !in_array($controller,array('pub','city','common','error'))  //公共页面不能跳
            && strpos($action,'ajax_')===false  //ajax请求不能跳
            && !in_array($action,array('modify_idcard','left_menu','do_modify_idcard'))
            && St_Functions::is_url_need_verify()
            && $client_ip!=$_SERVER['SERVER_ADDR']

        )  //公共 页面和认证页面不能跳
        {
            $user = Model_Member::check_login();
            if(!empty($user['mid']))
            {

                $verifystatus = DB::select('verifystatus')->from('member')->where('mid','=',$user['mid'])->execute()->get('verifystatus');
                if($verifystatus!=2)
                {
                    header('Location:' . $GLOBALS['cfg_basehost'] . '/member/index/modify_idcard?force=1');
                    exit;
                }
            }

        }

    }
    /*
     * 显示模板
     * @param string $tpl,模板名
     * */
    public function display($tpl)
    {
        $file = '';
        //判断是否是标准模板
        if (!file_exists(APPPATH . '/views/' . $GLOBALS['cfg_templet'] . '/' . $tpl . '.php'))
        {
            $file = 'default/' . $tpl;
        }
        else
        {
            $file = "{$GLOBALS['cfg_templet']}/" . $tpl;
        }
        //判断是否是用户上传模板
        if (strpos($tpl, 'usertpl') !== false)
        {
            $file = $tpl;
            $tpl_info = explode('/',$tpl);
            $user_tpl = $tpl_info[1] ? $tpl_info[1] : '';
            $this->assign('user_tpl',$user_tpl);

        }
        $view = Stourweb_View::factory($file);
        //模板数据
        $this->assign("templetdata", $this->_data);

        foreach ($this->_data as $key => $value)
        {
            $view->set($key, $value);
            $view->set_global($key, $value);
        }


        $this->response->body($view->render());


    }
}